package com.xh.bussiness.course.controller;

import com.xh.bussiness.course.bean.request.CoursewareRequest;
import com.xh.bussiness.course.service.ICoursewareService;
import com.xh.core.bean.AjaxResult;
import com.xh.core.bean.XhPage;
import com.xh.core.constant.AjaxResultConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "备课接口")
@RestController
@RequestMapping("/teachbook/Courseware")
public class CoursewareController {
    @Autowired
    ICoursewareService coursewareService;

    @ApiOperation(value = "备课分页查询", notes = "备课分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bean", value = "备课信息", required = true, dataType = "coursewareRequest")
    })
    @PostMapping("/queryPage")
    public AjaxResult queryPage(@RequestBody CoursewareRequest request) {
        XhPage page = new XhPage();
        page.setCurrent(request.getCurrent());
        page.setSize(request.getSize());

        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, coursewareService.queryPage(page, request));
    }

    @ApiOperation(value = "备课更新", notes = "备课更新")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bean", value = "备课信息", required = true, dataType = "coursewareRequest")
    })
    @PostMapping("/modify")
    @ResponseBody
    public AjaxResult modify(CoursewareRequest request) {
        if(null == request.getId()){
            return new AjaxResult(AjaxResultConstant.Result.ERROR, "参数错误：id不能为空");
        }
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, coursewareService.modify(request));
    }

    @ApiOperation(value = "备课保存", notes = "备课保存")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bean", value = "备课信息", required = true, dataType = "coursewareRequest")
    })
    @PostMapping("/save")
    @ResponseBody
    public AjaxResult save(CoursewareRequest request) {
        if(null == request.getCourseId() || null == request.getCourseIndexId()){
            return new AjaxResult(AjaxResultConstant.Result.ERROR, "参数错误");
        }
        return new AjaxResult(AjaxResultConstant.Result.SUCCESS, coursewareService.saveCourseware(request));
    }
}
